#include "stdafx.h"
#include "Module.h"
#include "Renderer.h"
#include "Application.h"


Application::Application(void)
{
	windowWidth = 800;
	windowHeight = 600;
	fullscreen = false;
	title = "Sparky engine: Sample app";
}


Application::Application(int width, int height, bool isFullscreen) 
{
	windowWidth = width;
	windowHeight = height;
	fullscreen = isFullscreen;
	title = "Sparky engine: Sample app";
}


Application::~Application(void)
{
}




int Application::run() 
{
	this->running = true;

	this->init();
	while(running) 
	{
		this->loop();
	}
	this->exit();
	return 0;
}


void Application::init() 
{
	this->modules["renderer"] = new Renderer(this);

	for (std::map<std::string, Module*>::iterator it = this->modules.begin(); it != this->modules.end(); ++it)
	{
		it->second->init();
	}
}


void Application::loop()
{
	for (std::map<std::string, Module*>::iterator it = this->modules.begin(); it != this->modules.end(); ++it)
	{
		it->second->work();
	}
}


void Application::exit()
{
	for (std::map<std::string, Module*>::iterator it = this->modules.begin(); it != this->modules.end(); ++it)
	{
		it->second->deinit();
	}
}


void Application::terminate() 
{
	this->running = false;
}


/*********************************** GETTERS ********************************/

int Application::getWidth() 
{
	return this->windowWidth;
}

int Application::getHeight()
{
	return this->windowHeight;
}

bool Application::getFullScreen()
{
	return this->fullscreen;
}

std::string Application::getTitle()
{
	return this->title;
}


/*********************************** SETTERS ********************************/

void Application::setTitle(std::string newTitle) 
{
	this->title = newTitle;
}

void Application::setWidth(int width)
{
	this->windowWidth = width;
}

void Application::setHeight(int height)
{
	this->windowHeight = height;
}

void Application::setFullScreen(bool fullscreen)
{
	this->fullscreen = fullscreen;
}

